<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function arr(nums) {
      const positive = nums.filter((num) => num > 0)
      const negative = nums.filter((num) => num < 0)
      let i = 0;
      const result = [];
      while (i < nums.length / 2) {
        Array.prototype.push.call(result, positive[i], negative[i]);
        i++;
      }
      return result;
    };
    console.log(arr([3, 1, -2, -5, 2, -4]));
  </script>
</body>

</html>